package com.vhly.bpplat.util;

import org.kxml2.kdom.Element;

import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: vhly[FR]
 * Date: 2010-3-3
 * Time: 17:32:44
 */
public final class DOMUtil {
    public static Element[] getElementsByName(Element root ,String namespace, String name){
        Element[] ret = null;
        Vector<Element> els = new Vector<Element>();
        int count = root.getChildCount();
        if(count > 0){
            for(int i = 0;i<count;i++){
                Object child = root.getChild(i);
                if(child instanceof Element){
                    Element el = (Element) child;
                    String n = el.getName();
                    if(n.equals(name)){
                        els.add(el);
                    }
                }
            }
        }
        if(!els.isEmpty()){
            ret = new Element[els.size()];
            els.copyInto(ret);
        }
        els.removeAllElements();
        return ret;
    }
}
